package com.aop.controller;

import com.aop.entities.Payment;
import com.aop.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.UUID;

/**
 * @Author: tgy
 * @Date: 2020-08-11 18:49
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @GetMapping("/pay")
    public String pay(){

        return orderService.pay(UUID.randomUUID().toString());
    }

    @GetMapping("addPay")
    public String addPay(){

        orderService.insertPayment();
        return  "add pay success";
    }

    @GetMapping("/addPayment/{type}")
    public Payment addPay(@PathVariable("type") Integer type) throws Exception{

        return orderService.insertPayment(type);
    }

    @GetMapping("/updatePayment/{id}")
    public String updatePayment(@PathVariable("id")Integer paymentId){

        Payment lisi = new Payment(paymentId, "lisi", null);

        boolean updateFlags = orderService.updatePayment(lisi);

        if (updateFlags){


            return "update success";
        }else {

            return "update fail";
        }

    }
}
